package com.gisuni.sddc.util;

import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;

import sun.management.counter.Variability;

public class GeneralCallService {
	/*
	 * 获取所有车辆信息
	 */
	public static String GetVehcileInfo() throws IOException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("cmd", "userVehicleList");

		Map<String, String> map1 = new HashMap<String, String>();
		map1.put("devKey", CommConfig.devKey);
		map1.put("userName", CommConfig.GeneralLoginName);
		map1.put("password", CommConfig.GeneralPwd);
		
		map.put("auth", map1);
		
		Map<String, String> map2 = new HashMap<String, String>();
		map2.put("objAuthType", "");
		map2.put("pageNo", "0");
		map2.put("onePageNum", "1000");
		
		map.put("params", map2);
		
		JSONObject json=new JSONObject(map);
		
		// 开始调用接口
		String res="";
		try {
			res = HttpUtil.HttpsPost(CommConfig.GeneralUrl,json.toString());
		} catch (KeyManagementException | NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return res;
	}
	
	public static String GetOneVehcileInfo(String strKey) throws IOException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("cmd", "queryVehicleInfo");

		Map<String, String> map1 = new HashMap<String, String>();
		map1.put("devKey", CommConfig.devKey);
		map1.put("userName", CommConfig.GeneralLoginName);
		map1.put("password", CommConfig.GeneralPwd);
		
		map.put("auth", map1);
		
		Map<String, String> map2 = new HashMap<String, String>();
		map2.put("vehicleId", strKey);
		
		map.put("params", map2);
		
		JSONObject json=new JSONObject(map);
		
		// 开始调用接口
		String res="";
		try {
			res = HttpUtil.HttpsPost(CommConfig.GeneralUrl,json.toString());
		} catch (KeyManagementException | NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return res;
	}
	
	public static String GetOneVehcileDynamicInfo(String strKey) throws IOException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("cmd", "vehicleDynamicInfo");

		Map<String, String> map1 = new HashMap<String, String>();
		map1.put("devKey", CommConfig.devKey);
		map1.put("userName", CommConfig.GeneralLoginName);
		map1.put("password", CommConfig.GeneralPwd);
		
		map.put("auth", map1);
		
		Map<String, String> map2 = new HashMap<String, String>();
		map2.put("objId", strKey);
		
		map.put("params", map2);
		
		JSONObject json=new JSONObject(map);
		
		// 开始调用接口
		String res="";
		try {
			res = HttpUtil.HttpsPost(CommConfig.GeneralUrl,json.toString());
		} catch (KeyManagementException | NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return res;
	}
	
	public static String GetVehcileHistory(String strKey,String bTime,String eTime) throws IOException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("cmd", "segTrackPressData");

		Map<String, String> map1 = new HashMap<String, String>();
		map1.put("devKey", CommConfig.devKey);
		map1.put("userName", CommConfig.GeneralLoginName);
		map1.put("password", CommConfig.GeneralPwd);
		
		map.put("auth", map1);
		
		Map<String, String> map2 = new HashMap<String, String>();
		map2.put("objId", strKey);
		map2.put("beginTime", bTime);
		map2.put("endTime", eTime);
		
		map.put("params", map2);
		
		JSONObject json=new JSONObject(map);
		
		// 开始调用接口
		String res="";
		try {
			res = HttpUtil.HttpsPost(CommConfig.GeneralUrl,json.toString());
		} catch (KeyManagementException | NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return res;
	}
}
